﻿Public Class FrmTravauxEffectues
#Region "champs"
    Dim idTrav As Integer
    Dim position As Integer
    Dim estplus As Boolean
    Dim estplus2 As Boolean
    Dim qte As Integer
    Dim prix As Decimal
    Dim idint As Integer
    Dim pri, qt, nomt As String
    Dim macnx As New PPE3.ClassMySqlConnect("853339_depanneur", "071064")
    Dim nbchamps As Integer = 0
    Dim i As Integer = 0
    Dim neuf As Boolean
#End Region
    Private Sub FrmTravauxEffectues_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = FrmStart
        Me.Top = 0
        Me.Left = 682
        TextBoxidTravaux.Text = "0"
        macnx.Se_Connecter_MySqlServer()


        dgvCalcule.DataSource = Nothing
        macnx.viderVue("Toutm")
        dgvCalcule.DataSource = macnx.Executer_Requete_Select("select * from calcule ", "Toutm")

        DataGridTravaux.DataSource = Nothing
        dgvMatNeuf.DataSource = Nothing
        macnx.viderVue("IdTravauxTarif")
        macnx.viderVue("RecMat")
        DataGridTravaux.DataSource = RemplaceSlashApostrophesDataTable(macnx.Executer_Requete_Select("SELECT IdTravauxTarif as NumeroTravail, NomTravaux, PrixTtc FROM travauxTarif", "IdTravauxTarif"))

        dgvMatNeuf.DataSource = Nothing
        macnx.viderVue("ToutmaterielNeuf")
        dgvMatNeuf.DataSource = macnx.Executer_Requete_Select("select * from materielneuf where ReferenceMaterielNeuf LIKE '" & tbRechercheNeuf.Text & "%'", "ToutmaterielNeuf")
        CacherColonne(dgvMatNeuf, "idmaterielNeuf")
        CacherColonne(dgvMatNeuf, "prixMaterielNeuf")

        dgvMatOcca.DataSource = Nothing
        macnx.viderVue("ToutmaterielOcca")
        dgvMatOcca.DataSource = macnx.Executer_Requete_Select("select idmateriel,nommateriel,prixmateriel as Prix ,quantiter as QTE,reference,numerocategories,nomcategorie  as Categorie from materielOcass,categoriemateriel where (materielOcass.numeroCategories=categoriemateriel.NumeroCategorie) and NomMateriel LIKE '%" & tbRechercheOcca.Text & "%'", "ToutmaterielOcca")
        CacherColonne(dgvMatOcca, "IdMateriel")
        CacherColonne(dgvMatOcca, "numeroCategories")

        macnx.Se_Deconnecter_MySqlServer()
        DataGridTravaux.Font = lblTab.Font
        DataGridTravaux.AutoResizeColumns()
        Me.DataGridTravaux.RowTemplate.Height = 15
        estplus = True
        estplus2 = True
        TextBoxidTravaux.Text = 0
    End Sub

#Region "Fonction"

    Public Sub CacherColonne(data As DataGridView, colonne As String)

        data.Columns(colonne).Visible = False

    End Sub

    Public Function RemplaceApostrophesSlash(ByRef unechaine As String) As String
        Dim ch As String
        ch = unechaine.Replace("'", "/")
        Return ch
    End Function


    Public Function RemplaceSlashApostrophes(ByRef unechaine As String) As String
        Dim ch As String
        ch = unechaine.Replace("/", "'")
        Return ch
    End Function

    Public Function RemplaceSlashApostrophesDataTable(ByRef lesdonnees As DataTable)
        Dim nblignes As Integer
        Dim nbcolonnes As Integer
        Dim test As String = ""
        nblignes = lesdonnees.Rows.Count
        nbcolonnes = lesdonnees.Columns.Count
        Dim i, j As Integer
        For i = 0 To nblignes - 1
            For j = 0 To nbcolonnes - 1
                'Attention le replace ne s'applique qu'aux type String : utilisation de la classe de base Object :
                If Object.ReferenceEquals(lesdonnees.Rows(i).Item(j).GetType(), test.GetType()) Then
                    lesdonnees.Rows(i).Item(j) = RemplaceSlashApostrophes(lesdonnees.Rows(i).Item(j))
                End If
            Next
        Next
        Return lesdonnees
    End Function
#End Region

    Private Sub DataGridTravaux_Click(sender As Object, e As System.EventArgs) Handles DataGridTravaux.Click
        Try

            Dim id As Object = 0
            Me.TextBoxidTravaux.Text = Me.DataGridTravaux.SelectedCells.Item(index:=id).Value.ToString

        Catch ex As Exception

        End Try
    End Sub

    'Private Sub TextBoxidTravaux_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBoxidTravaux.TextChanged
    '    If TextBoxidTravaux.Text = "0" Then
    '        TextBoxNomTravaux.Text = ""
    '        TextBoxPrixTravaux.Text = ""
    '    Else
    '        Try
    '            idTrav = TextBoxidTravaux.Text
    '        Catch ex As InvalidCastException

    '        End Try
    '          macnx.Se_Connecter_MySqlServer()
    '        DataGridTravaux.DataSource = RemplaceSlashApostrophesDataTable(macnx.Executer_Requete_Select("SELECT IdTravauxTarif as NumeroTravail, NomTravaux, PrixTtc FROM travauxTarif Where IdTravauxTarif = '" & idTrav & "'"))
    '        DataGridTravaux.AutoResizeColumns()
    '        DataGridTravaux.ClearSelection()
    '        Rafraichir()
    '        macnx.Se_Deconnecter_MySqlServer()
    '        'RechargerLesDonnees()
    '    End If
    'End Sub
    'Public Sub RechargerLesDonnees()
    '    macnx.Se_Connecter_MySqlServer()
    '    macnx.Vider_Dataset()
    '    DataGridTravaux.DataSource = macnx.Executer_Requete_Select("SELECT idTravauxTarif as NumeroTravail, NomTravaux, PrixTtc FROM travauxTarif")
    '    DataGridTravaux.ClearSelection()
    '    DataGridTravaux.AutoResizeColumns()
    '    macnx.Se_Deconnecter_MySqlServer()
    'End Sub
    Public Sub Rafraichir()
        Try
            Dim donnees As New Data.DataTable
            macnx.viderVue("NomTravaux")
            donnees = macnx.Executer_Requete_Select("SELECT NomTravaux, PrixTtc FROM travauxTarif Where IdTravauxTarif = '" & idTrav & "'", "NomTravaux")
            nbchamps = donnees.Rows.Count - 1
            TextBoxNomTravaux.Text = macnx.GetChamp_DataTable(donnees, position, 0)
            TextBoxPrixTravaux.Text = RemplaceSlashApostrophes(macnx.GetChamp_DataTable(donnees, position, 1))

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BtnAjout_Click(sender As System.Object, e As System.EventArgs) Handles BtnAjout.Click
        If TextBoxNomTravaux.Text <> "" Then


            estplus = True
            If FrmRecapAjoutDep.lbl1.Text = "" Then
                FrmRecapAjoutDep.lbl1.Text = TextBoxNomTravaux.Text
                FrmRecapAjoutDep.lbl101.Text = textboxQte.Value
                FrmRecapAjoutDep.lbl102.Text = TextBoxPrixTravaux.Text
                FrmRecapAjoutDep.lbl1.Visible = True
                FrmRecapAjoutDep.lbl101.Visible = True
                FrmRecapAjoutDep.lbl102.Visible = True
                estplus = False
            End If
            If FrmRecapAjoutDep.lbl1.Text <> "" And FrmRecapAjoutDep.lbl2.Text = "" And estplus = True Then
                FrmRecapAjoutDep.lbl2.Text = TextBoxNomTravaux.Text
                FrmRecapAjoutDep.lbl201.Text = textboxQte.Value
                FrmRecapAjoutDep.lbl202.Text = TextBoxPrixTravaux.Text
                FrmRecapAjoutDep.lbl2.Visible = True
                FrmRecapAjoutDep.lbl201.Visible = True
                FrmRecapAjoutDep.lbl202.Visible = True
                estplus = False
            End If
            If FrmRecapAjoutDep.lbl1.Text <> "" And FrmRecapAjoutDep.lbl2.Text <> "" And FrmRecapAjoutDep.lbl3.Text = "" And estplus = True Then
                FrmRecapAjoutDep.lbl3.Text = TextBoxNomTravaux.Text
                FrmRecapAjoutDep.lbl301.Text = textboxQte.Value
                FrmRecapAjoutDep.lbl302.Text = TextBoxPrixTravaux.Text
                FrmRecapAjoutDep.lbl3.Visible = True
                FrmRecapAjoutDep.lbl301.Visible = True
                FrmRecapAjoutDep.lbl302.Visible = True
                estplus = False
            End If
            If FrmRecapAjoutDep.lbl1.Text <> "" And FrmRecapAjoutDep.lbl2.Text <> "" And FrmRecapAjoutDep.lbl3.Text <> "" And FrmRecapAjoutDep.lbl4.Text = "" And estplus = True Then
                FrmRecapAjoutDep.lbl4.Text = TextBoxNomTravaux.Text
                FrmRecapAjoutDep.lbl401.Text = textboxQte.Value
                FrmRecapAjoutDep.lbl402.Text = TextBoxPrixTravaux.Text
                FrmRecapAjoutDep.lbl4.Visible = True
                FrmRecapAjoutDep.lbl401.Visible = True
                FrmRecapAjoutDep.lbl402.Visible = True
                estplus = False
            End If
            If FrmRecapAjoutDep.lbl1.Text <> "" And FrmRecapAjoutDep.lbl2.Text <> "" And FrmRecapAjoutDep.lbl3.Text <> "" And FrmRecapAjoutDep.lbl4.Text <> "" And FrmRecapAjoutDep.lbl5.Text = "" And estplus = True Then
                FrmRecapAjoutDep.lbl5.Text = TextBoxNomTravaux.Text
                FrmRecapAjoutDep.lbl501.Text = textboxQte.Value
                FrmRecapAjoutDep.lbl502.Text = TextBoxPrixTravaux.Text
                FrmRecapAjoutDep.lbl5.Visible = True
                FrmRecapAjoutDep.lbl501.Visible = True
                FrmRecapAjoutDep.lbl502.Visible = True
                estplus = False
            End If
            If FrmRecapAjoutDep.lbl1.Text <> "" And FrmRecapAjoutDep.lbl2.Text <> "" And FrmRecapAjoutDep.lbl3.Text <> "" And FrmRecapAjoutDep.lbl4.Text <> "" And FrmRecapAjoutDep.lbl5.Text <> "" And FrmRecapAjoutDep.lbl6.Text = "" And estplus = True Then
                FrmRecapAjoutDep.lbl6.Text = TextBoxNomTravaux.Text
                FrmRecapAjoutDep.lbl601.Text = textboxQte.Value
                FrmRecapAjoutDep.lbl602.Text = TextBoxPrixTravaux.Text
                FrmRecapAjoutDep.lbl6.Visible = True
                FrmRecapAjoutDep.lbl601.Visible = True
                FrmRecapAjoutDep.lbl602.Visible = True
                estplus = False
            End If
            If FrmRecapAjoutDep.lbl1.Text <> "" And FrmRecapAjoutDep.lbl2.Text <> "" And FrmRecapAjoutDep.lbl3.Text <> "" And FrmRecapAjoutDep.lbl4.Text <> "" And FrmRecapAjoutDep.lbl5.Text <> "" And FrmRecapAjoutDep.lbl6.Text <> "" And FrmRecapAjoutDep.lbl7.Text = "" And estplus = True Then
                FrmRecapAjoutDep.lbl7.Text = TextBoxNomTravaux.Text
                FrmRecapAjoutDep.lbl701.Text = textboxQte.Value
                FrmRecapAjoutDep.lbl702.Text = TextBoxPrixTravaux.Text
                FrmRecapAjoutDep.lbl7.Visible = True
                FrmRecapAjoutDep.lbl701.Visible = True
                FrmRecapAjoutDep.lbl702.Visible = True
                estplus = False
            End If
            If FrmRecapAjoutDep.lbl1.Text <> "" And FrmRecapAjoutDep.lbl2.Text <> "" And FrmRecapAjoutDep.lbl3.Text <> "" And FrmRecapAjoutDep.lbl4.Text <> "" And FrmRecapAjoutDep.lbl5.Text <> "" And FrmRecapAjoutDep.lbl6.Text <> "" And FrmRecapAjoutDep.lbl7.Text <> "" And FrmRecapAjoutDep.lbl8.Text = "" And estplus = True Then
                FrmRecapAjoutDep.lbl8.Text = TextBoxNomTravaux.Text
                FrmRecapAjoutDep.lbl801.Text = textboxQte.Value
                FrmRecapAjoutDep.lbl802.Text = TextBoxPrixTravaux.Text
                FrmRecapAjoutDep.lbl8.Visible = True
                FrmRecapAjoutDep.lbl801.Visible = True
                FrmRecapAjoutDep.lbl802.Visible = True
                estplus = False
            End If


            If BtnAjout.Text = "Ajouter" Then
                idint = FrmRecapAjoutDep.lblIdInt.Text
                nomt = macnx.RemplaceCoteParVide(TextBoxNomTravaux.Text)
                qt = textboxQte.Text
                pri = TextBoxPrixTravaux.Text
                macnx.Se_Connecter_MySqlServer()
                Dim requet As String = " Insert into travauxeffectues Values( " & idint & ",'" & nomt & "', '" & qt & "', 'Par Defaut' ,  '" & pri & "' ,  true , 'Par Defaut', true)"
                macnx.Executer_Requete_Action(requet)
                macnx.Se_Deconnecter_MySqlServer()
                'RechargerLesDonnees()

                TextBoxNomTravaux.Text = ""
                TextBoxPrixTravaux.Text = ""
            End If
        End If
    End Sub

    Private Sub BtnAjout2_Click(sender As System.Object, e As System.EventArgs) Handles BtnAjout2.Click
        If TextBoxNomTravaux2.Text <> "" Then

            Dim qqq As String
            Dim hhh As String
            macnx.Se_Connecter_MySqlServer()
            Dim test As String = macnx.ExecuteScalar("SELECT idmaterielNeuf FROM materielneuf WHERE ReferenceMaterielNeuf like '" & TextBoxNumS.Text & "'")
            macnx.Se_Deconnecter_MySqlServer()
            If test = Nothing Then
                neuf = True
            End If

            If neuf = False Then
                qqq = textboxQte2.Value.ToString
                hhh = dgvMatOcca.CurrentRow.Cells(3).Value.ToString()
            Else
                qqq = "0"
                hhh = "1"
            End If
            If qqq <= hhh Then

                estplus2 = True
                Dim trav As String = TextBoxNumS.Text & " - " & TextBoxNomTravaux2.Text
                If FrmRecapAjoutDep.lbl9.Text = "" Then
                    FrmRecapAjoutDep.lbl9.Text = trav
                    FrmRecapAjoutDep.lbl91.Text = textboxQte2.Value
                    FrmRecapAjoutDep.lbl92.Text = TextBoxPrixTravaux2.Text
                    FrmRecapAjoutDep.lbl9.Visible = True
                    FrmRecapAjoutDep.lbl91.Visible = True
                    FrmRecapAjoutDep.lbl92.Visible = True
                    estplus2 = False
                End If
                If FrmRecapAjoutDep.lbl9.Text <> "" And FrmRecapAjoutDep.lbl10.Text = "" And estplus2 = True Then
                    FrmRecapAjoutDep.lbl10.Text = trav
                    FrmRecapAjoutDep.lbl1001.Text = textboxQte2.Value
                    FrmRecapAjoutDep.lbl1002.Text = TextBoxPrixTravaux2.Text
                    FrmRecapAjoutDep.lbl10.Visible = True
                    FrmRecapAjoutDep.lbl1001.Visible = True
                    FrmRecapAjoutDep.lbl1002.Visible = True
                    estplus2 = False
                End If
                If FrmRecapAjoutDep.lbl9.Text <> "" And FrmRecapAjoutDep.lbl10.Text <> "" And FrmRecapAjoutDep.lbl11.Text = "" And estplus2 = True Then
                    FrmRecapAjoutDep.lbl11.Text = trav
                    FrmRecapAjoutDep.lbl111.Text = textboxQte2.Value
                    FrmRecapAjoutDep.lbl112.Text = TextBoxPrixTravaux2.Text
                    FrmRecapAjoutDep.lbl11.Visible = True
                    FrmRecapAjoutDep.lbl111.Visible = True
                    FrmRecapAjoutDep.lbl112.Visible = True
                    estplus2 = False
                End If
                If FrmRecapAjoutDep.lbl9.Text <> "" And FrmRecapAjoutDep.lbl10.Text <> "" And FrmRecapAjoutDep.lbl11.Text <> "" And FrmRecapAjoutDep.lbl12.Text = "" And estplus2 = True Then
                    FrmRecapAjoutDep.lbl12.Text = trav
                    FrmRecapAjoutDep.lbl121.Text = textboxQte2.Value
                    FrmRecapAjoutDep.lbl122.Text = TextBoxPrixTravaux2.Text
                    FrmRecapAjoutDep.lbl12.Visible = True
                    FrmRecapAjoutDep.lbl121.Visible = True
                    FrmRecapAjoutDep.lbl122.Visible = True
                    estplus2 = False
                End If
                If FrmRecapAjoutDep.lbl9.Text <> "" And FrmRecapAjoutDep.lbl10.Text <> "" And FrmRecapAjoutDep.lbl11.Text <> "" And FrmRecapAjoutDep.lbl12.Text <> "" And FrmRecapAjoutDep.lbl13.Text = "" And estplus2 = True Then
                    FrmRecapAjoutDep.lbl13.Text = trav
                    FrmRecapAjoutDep.lbl131.Text = textboxQte2.Value
                    FrmRecapAjoutDep.lbl132.Text = TextBoxPrixTravaux2.Text
                    FrmRecapAjoutDep.lbl13.Visible = True
                    FrmRecapAjoutDep.lbl131.Visible = True
                    FrmRecapAjoutDep.lbl132.Visible = True
                    estplus2 = False
                End If
                If FrmRecapAjoutDep.lbl9.Text <> "" And FrmRecapAjoutDep.lbl10.Text <> "" And FrmRecapAjoutDep.lbl11.Text <> "" And FrmRecapAjoutDep.lbl12.Text <> "" And FrmRecapAjoutDep.lbl13.Text <> "" And FrmRecapAjoutDep.lbl14.Text = "" And estplus2 = True Then
                    FrmRecapAjoutDep.lbl14.Text = trav
                    FrmRecapAjoutDep.lbl141.Text = textboxQte2.Value
                    FrmRecapAjoutDep.lbl142.Text = TextBoxPrixTravaux2.Text
                    FrmRecapAjoutDep.lbl14.Visible = True
                    FrmRecapAjoutDep.lbl141.Visible = True
                    FrmRecapAjoutDep.lbl142.Visible = True
                    estplus2 = False
                End If
                If FrmRecapAjoutDep.lbl9.Text <> "" And FrmRecapAjoutDep.lbl10.Text <> "" And FrmRecapAjoutDep.lbl11.Text <> "" And FrmRecapAjoutDep.lbl12.Text <> "" And FrmRecapAjoutDep.lbl13.Text <> "" And FrmRecapAjoutDep.lbl14.Text <> "" And FrmRecapAjoutDep.lbl15.Text = "" And estplus2 = True Then
                    FrmRecapAjoutDep.lbl15.Text = trav
                    FrmRecapAjoutDep.lbl151.Text = textboxQte2.Value
                    FrmRecapAjoutDep.lbl152.Text = TextBoxPrixTravaux2.Text
                    FrmRecapAjoutDep.lbl15.Visible = True
                    FrmRecapAjoutDep.lbl151.Visible = True
                    FrmRecapAjoutDep.lbl152.Visible = True
                    estplus2 = False
                End If
                If FrmRecapAjoutDep.lbl9.Text <> "" And FrmRecapAjoutDep.lbl10.Text <> "" And FrmRecapAjoutDep.lbl11.Text <> "" And FrmRecapAjoutDep.lbl12.Text <> "" And FrmRecapAjoutDep.lbl13.Text <> "" And FrmRecapAjoutDep.lbl14.Text <> "" And FrmRecapAjoutDep.lbl15.Text <> "" And FrmRecapAjoutDep.lbl16.Text = "" And estplus2 = True Then
                    FrmRecapAjoutDep.lbl16.Text = trav
                    FrmRecapAjoutDep.lbl161.Text = textboxQte2.Value
                    FrmRecapAjoutDep.lbl162.Text = TextBoxPrixTravaux2.Text
                    FrmRecapAjoutDep.lbl16.Visible = True
                    FrmRecapAjoutDep.lbl161.Visible = True
                    FrmRecapAjoutDep.lbl162.Visible = True
                    estplus2 = False
                End If
                If BtnAjout2.Text = "Ajouter" Then



                    idint = FrmRecapAjoutDep.lblIdInt.Text
                    nomt = TextBoxNumS.Text & " - " & TextBoxNomTravaux2.Text
                    qt = textboxQte2.Text
                    pri = TextBoxPrixTravaux2.Text

                    macnx.Se_Connecter_MySqlServer()

                    Dim requet As String = "Insert into travauxeffectues Values(  " & idint & ",'" & nomt & "', '" & qt & "', 'Par Defaut' ,  '" & pri & "' ,  false , 'Par Defaut', " & neuf & ")"
                    macnx.Executer_Requete_Action(requet)

                    If neuf <> True Then



                        Dim qte As String = (dgvMatOcca.CurrentRow.Cells(3).Value.ToString() - (textboxQte2.Value.ToString))

                        macnx.Executer_Requete_Action("UPDATE materielocass SET Quantiter= '" & qte & "' WHERE IdMateriel = '" & dgvMatOcca.CurrentRow.Cells(0).Value.ToString() & "'")



                        Dim qteTest As String = macnx.ExecuteScalar("SELECT Quantiter FROM materielocass WHERE IdMateriel = '" & dgvMatOcca.CurrentRow.Cells(0).Value.ToString() & "'")





                        If qteTest <= 0 Then
                            macnx.Executer_Requete_Action("DELETE FROM materielocass WHERE IdMateriel = '" & dgvMatOcca.CurrentRow.Cells(0).Value.ToString() & "'")
                        End If
                    End If
                    dgvMatOcca.DataSource = Nothing
                    macnx.viderVue("ToutmaterielOcca")
                    dgvMatOcca.DataSource = macnx.Executer_Requete_Select("select idmateriel,nommateriel,prixmateriel as Prix ,quantiter as QTE,reference,numerocategories,nomcategorie  as Categorie from materielOcass,categoriemateriel where (materielOcass.numeroCategories=categoriemateriel.NumeroCategorie)", "ToutmaterielOcca")
                    CacherColonne(dgvMatOcca, "IdMateriel")
                    CacherColonne(dgvMatOcca, "numeroCategories")

                    macnx.Se_Deconnecter_MySqlServer()
                    'RechargerLesDonnees()
                    TextBoxNomTravaux2.Text = ""
                    TextBoxPrixTravaux2.Text = ""
                    textboxQte2.Value = 1
                    TextBoxNumS.Text = ""

                End If
            End If
        End If
    End Sub

    Private Sub DataGridTravaux_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridTravaux.CellClick
        TextBoxNomTravaux.Text = DataGridTravaux.CurrentRow.Cells(1).Value.ToString()
        TextBoxPrixTravaux.Text = DataGridTravaux.CurrentRow.Cells(2).Value.ToString()
    End Sub


    Private Sub DataGridViewMateriels_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvMatNeuf.CellClick
        neuf = True
        Dim Ok As Boolean = False
        Dim prix As String = dgvMatNeuf.CurrentRow.Cells(4).Value.ToString()
        Dim tva As String
        If prix <> "" Then

            While Ok = False

                Dim Com As String = dgvCalcule.Rows(i).Cells(1).Value.ToString()

                If CDec(prix) < CDec(Com) Then
                    i = i + 1
                Else
                    Ok = True
                    macnx.Se_Connecter_MySqlServer()
                    tva = macnx.ExecuteScalar("SELECT tva FROM tva WHERE idtva = 1")
                    macnx.Se_Deconnecter_MySqlServer()
                    Dim multi As String = CDec(prix) * dgvCalcule.Rows(i).Cells(2).Value.ToString * tva

                    TextBoxPrixTravaux2.Text = multi
                    i = 0

                End If

            End While
        End If


        TextBoxNumS.Text = dgvMatNeuf.CurrentRow.Cells(1).Value.ToString()
        TextBoxNomTravaux2.Text = dgvMatNeuf.CurrentRow.Cells(2).Value.ToString()

    End Sub


    Private Sub tbRechercheNeuf_TextChanged(sender As System.Object, e As System.EventArgs) Handles tbRechercheNeuf.TextChanged
        macnx.Se_Connecter_MySqlServer()

        dgvMatNeuf.DataSource = Nothing
        macnx.viderVue("ToutmaterielNeuf")
        dgvMatNeuf.DataSource = macnx.Executer_Requete_Select("select * from materielneuf where ReferenceMaterielNeuf LIKE '" & tbRechercheNeuf.Text & "%'", "ToutmaterielNeuf")
        CacherColonne(dgvMatNeuf, "idmaterielNeuf")
        CacherColonne(dgvMatNeuf, "prixMaterielNeuf")

        macnx.Se_Deconnecter_MySqlServer()
    End Sub

    Private Sub tbRechercheOcca_TextChanged(sender As System.Object, e As System.EventArgs) Handles tbRechercheOcca.TextChanged
        macnx.Se_Connecter_MySqlServer()

        dgvMatOcca.DataSource = Nothing
        macnx.viderVue("ToutmaterielOcca")
        dgvMatOcca.DataSource = macnx.Executer_Requete_Select("select idmateriel,nommateriel,prixmateriel as Prix ,quantiter as QTE,reference,numerocategories,nomcategorie  as Categorie from materielOcass,categoriemateriel where (materielOcass.numeroCategories=categoriemateriel.NumeroCategorie) and NomMateriel LIKE '%" & tbRechercheOcca.Text & "%'", "ToutmaterielOcca")
        CacherColonne(dgvMatOcca, "IdMateriel")
        CacherColonne(dgvMatOcca, "numeroCategories")

        macnx.Se_Deconnecter_MySqlServer()
    End Sub

    Private Sub dgvMatOcca_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvMatOcca.CellClick
        neuf = False
        TextBoxNumS.Text = dgvMatOcca.CurrentRow.Cells(4).Value.ToString()
        TextBoxNomTravaux2.Text = dgvMatOcca.CurrentRow.Cells(1).Value.ToString()
        TextBoxPrixTravaux2.Text = dgvMatOcca.CurrentRow.Cells(2).Value.ToString()
    End Sub
End Class